/************************************************************************************
* Code lines 4-20 gotten from 
* http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html  
*************************************************************************************/
Object.prototype.Inherits = function( parent )
{
	if( arguments.length > 1 )
	{
		parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
	}
	else
	{
		parent.call( this );
	}
}
//code from http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html
Function.prototype.Inherits = function( parent )
{
	this.prototype = new parent();
	this.prototype.constructor = this;
}
/************************************************************************************/



//The Shape base class
<<<<<<< .mine
function Shape(){
	var startX, startY, endX, EndY,shapeString;
	var strokeStyle, lineJoin, lineWidth, shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur,fillStyle,font;
=======
function Shape(nm){
	var startX, StartY, endX, EndY, name;
	var strokeStyle, lineJoin, lineWidth, shadowColor, shadowOffsetX, shadowOffsetY, shadowBlur;
>>>>>>> .r20
	this.name = nm;
	this.setStyle = function(c, lj, lw){
		this.strokeStyle = c;
		this.lineJoin = lj;
		this.lineWidth = lw;
		this.shadowColor = "#ddd";
		this.shadowOffsetX = 1;
		this.shadowOffsetY = 1;
		this.shadowBlur = 4;
		this.fillStyle = c;
		this.font = "italic 30px sans-serif";
	}	
	
	//common for all drawing objects
	this.setStartLoc = function(x,y){
		this.startX = x;
		this.startY = y;
	}
	
	//common for all drawing ojbects
	this.setEndLoc = function(x,y){
		this.endX = x;
		this.endY = y;
    }

    //Only used in Text
    this.setString = function (s) {
            this.shapeString = s;
        }

	//implemented by derived classes
	this.draw = function(ctx){
		//implemented by derived classes
	}
}

Line.Inherits( Shape ); 
function Line(){
	this.Inherits( Shape, "Line");	
		
	this.draw = function (ctx){
		ctx.strokeStyle = this.strokeStyle;
		ctx.lineJoin = this.lineJoin;
		ctx.lineWidth = this.lineWidth;
		ctx.shadowColor = this.shadowColor;
		ctx.shadowOffsetX = this.shadowOffsetX;
		ctx.shadowOffsetY = this.shadowOffsetY;
		ctx.shadowBlur = this.shadowBlur;
		ctx.beginPath();
		ctx.moveTo(this.startX, this.startY);
		ctx.lineTo(this.endX, this.endY)
		ctx.closePath();
		ctx.stroke();
	}
}


Rectangle.Inherits( Shape );
function Rectangle(){
	this.Inherits( Shape, "Rectangle");
	
	this.draw = function(ctx){
		ctx.strokeStyle = this.strokeStyle;
		ctx.lineJoin = this.lineJoin;
		ctx.lineWidth = this.lineWidth;
		ctx.shadowColor = this.shadowColor;
		ctx.shadowOffsetX = this.shadowOffsetX;
		ctx.shadowOffsetY = this.shadowOffsetY;
		ctx.shadowBlur = this.shadowBlur;
		ctx.strokeRect(this.startX, this.startY, this.endX-this.startX, this.endY-this.startY);	
	}
}

Circle.Inherits(Shape);
function Circle(){
	this.Inherits( Shape, "Circle");
	
	this.difference = function(a,b){
		return (a > b)? a-b : b-a;
	}
	
	this.draw = function(ctx){
		ctx.strokeStyle = this.strokeStyle;
		ctx.lineJoin = this.lineJoin;
		ctx.lineWidth = this.lineWidth;
		ctx.shadowColor = this.shadowColor;
		ctx.shadowOffsetX = this.shadowOffsetX;
		ctx.shadowOffsetY = this.shadowOffsetY;
		ctx.shadowBlur = this.shadowBlur;
		ctx.beginPath();
		ctx.arc(this.startX,this.startY,this.difference(this.startX, this.endX),0,Math.PI*2,true);
		ctx.closePath();
		ctx.stroke();
	}
}






Pencil.Inherits(Shape);	
function Pencil(){
    this.Inherits(Shape, "Pencil");
	this.arrX = new Array();
	this.arrY = new Array();

	
	this.addCordinate = function(x, y){
		this.arrX.push(x);
		this.arrY.push(y);
	}
	
	this.draw = function(ctx){
		ctx.strokeStyle = this.strokeStyle;
		ctx.lineJoin = this.lineJoin;
		ctx.lineWidth = this.lineWidth;
		ctx.shadowColor = this.shadowColor;
		ctx.shadowOffsetX = this.shadowOffsetX;
		ctx.shadowOffsetY = this.shadowOffsetY;
		ctx.shadowBlur = this.shadowBlur;
		ctx.beginPath();
		ctx.moveTo(this.arrX[0], this.arrY[0]);
	
		for (var i = 1; i< (this.arrX.length -1); i++)
		{
			ctx.lineTo(this.arrX[i], this.arrY[i])
			ctx.stroke();
		}

		ctx.closePath();
    }
<<<<<<< .mine
}





Text.Inherits(Shape);
function Text(x, y) {
    this.Inherits(Shape, x, y);
    
    this.draw = function (ctx) {
        ctx.strokeStyle = this.strokeStyle;
        ctx.lineJoin = this.lineJoin;
        ctx.lineWidth = this.lineWidth;
        ctx.shadowColor = this.shadowColor;
        ctx.shadowOffsetX = this.shadowOffsetX;
        ctx.shadowOffsetY = this.shadowOffsetY;
        ctx.shadowBlur = this.shadowBlur;
        ctx.fillStyle = this.fillStyle;
        ctx.font = this.font;
        ctx.fillText(this.shapeString, this.startX, this.startY);
    }
}

//function displayResult() {
//    document.getElementById("b1").style.position = "absolute";
//    document.getElementById("b1").style.top = "100px";
//    document.getElementById("b1").style.left = "100px";
//}

// fyrirlestur, draggable
// function Circle(x,y){
	// this.x=x;
	// this.y=y;
	// this.innerShape = new Kinetic.shape(function(){
	// //TODO: draw a circle!!!
	// })
	// }
//And don't forget to implement a default constructor within each constructor function, by handling input arguments whose typeof() is "undefined".=======
}>>>>>>> .r20
